"""
语法:
    1. 普通元素定位:直接定位option标签
    2. Select类
        Select(select元素)
    - 通过索引获取
        Select(select元素).select_by_index(索引值) # 索引从0开始
    - 通过option选项的value属性定位
        Select(select元素).select_by_value(value索引值)
    - 通过option选项的文本值
        Select(select元素).select_by_visible_text("文本值")
"""

# 1. 导入模块
import os
from time import sleep
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By

# 2.创建浏览器对象并打开浏览器
driver = webdriver.Chrome()
driver.maximize_window()
file_path = os.path.abspath("练习页面/注册A.html")
driver.get(file_path)
sleep(3)
# 3.元素定位+元素操作
# 普通方法定位
# driver.find_element(By.XPATH, '//option[4]').click()

# Select类----索引
select_tag = driver.find_element(By.ID, "selectA")
Select(select_tag).select_by_index(2)
sleep(3)
# Select类----value
# Select(select_tag).select_by_value('sh')

# Select类----visible_text
Select(select_tag).select_by_visible_text("A重庆")
sleep(3)